﻿using System;
namespace ServicesDirectory.UserControl
{
    public partial class MessageBox : System.Web.UI.UserControl
    {
        /// <summary>
        /// Occurs when [yes].
        /// </summary>
        public event EventHandler Yes;
        /// <summary>
        /// Occurs when [no].
        /// </summary>
        public event EventHandler No;
        /// <summary>
        /// Occurs when [ok].
        /// </summary>
        public event EventHandler Ok;
        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            btnNo.Click += btnNo_Click;
            btnYes.Click += btnYes_Click;
            btnOk.Click += BtnOk_Click;

            if(!IsPostBack)
            {
                lblTitleMessage.Text = Request.Url.Host + " say:";
            }
        }

        /// <summary>
        /// Handles the Click event of the BtnOk control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        void BtnOk_Click(object sender, EventArgs e)
        {
            if (Ok != null)
                Ok(sender, e);
        }

        /// <summary>
        /// Handles the Click event of the btnYes control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        void btnYes_Click(object sender, EventArgs e)
        {
            if (Yes != null)
                Yes(sender, e);
        }

        /// <summary>
        /// Handles the Click event of the btnNo control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        void btnNo_Click(object sender, EventArgs e)
        {
            if (No != null)
                No(sender, e);
        }
        /// <summary>
        /// Shows the button.
        /// </summary>
        /// <param name="mode">1. show button YES and NO
        /// 2. Show button OK</param>
        public void ShowButton(int mode)
        {
            switch (mode)
            {
                case 1:
                    btnYes.Visible = true;
                    btnNo.Visible = true;
                    btnOk.Visible = false;
                    break;
                case 2:
                    btnYes.Visible = false;
                    btnNo.Visible = false;
                    btnOk.Visible = true;
                    break;
                
                default:
                    btnYes.Visible = true;
                    btnNo.Visible = true;
                    btnOk.Visible = false;
                    break;
            }
        }

        /// <summary>
        /// Sets the title.
        /// </summary>
        /// <param name="message">The message.</param>
        public void SetTitle(string message)
        {

            lblMessage.Text = message;
        }
        /// <summary>
        /// Set title and set icon for message
        /// </summary>
        /// <param name="message">display message</param>
        /// <param name="icon">1.icon info
        /// 2.icon question
        /// 3.icon error
        /// 4.icon warning</param>
        public void SetTitle(string message, int icon)
        {
            imgIcon.Visible = true;
            lblMessage.Text = message;
            switch (icon)
            {
                case 1:
                    imgIcon.ImageUrl = "../Resources/Images/Infoicon.png";
                    break;
                case 2:
                    imgIcon.ImageUrl = "../Resources/Images/ButtonHelpicon.png";
                    break;
                case 3:
                    imgIcon.ImageUrl = "../Resources/Images/Closeicon.png";
                    break;
                case 4:
                    imgIcon.ImageUrl = "../Resources/Images/AlarmWarning.png";
                    break;
                default:
                    imgIcon.ImageUrl = "../Resources/Images/Infoicon.png";
                    break;
            }
        }
    }
}